package gvo.image.try1;

public class ImageViewer extends javax.swing.JFrame {
	 private javax.swing.JDesktopPane desktop;
    
    public ImageViewer() {
        initComponents();
        pack();
        setBounds( 100, 100, 400, 400 );
    }

  
    private void initComponents() {
        desktop = new javax.swing.JDesktopPane();
        

        setTitle("Image Viewer");
        addWindowListener(new java.awt.event.WindowAdapter() {
            public void windowClosing(java.awt.event.WindowEvent evt) {
                exitForm(evt);
            }
        });
        getContentPane().add(desktop, java.awt.BorderLayout.CENTER);
	/*
        getAccessibleContext().setAccessibleName("Image Viewer Frame");
        
        desktop.getAccessibleContext().setAccessibleName("Image Desktop");
        desktop.getAccessibleContext().setAccessibleDescription("Image desktop");
	*/
       
        
    }
    public void openImageViaDialog() {
        javax.swing.JFileChooser chooser = new javax.swing.JFileChooser();
        chooser.addChoosableFileFilter(new ImageFileFilter());
        int option = chooser.showOpenDialog(this);
        if (option == javax.swing.JFileChooser.APPROVE_OPTION) {
            java.io.File file = chooser.getSelectedFile();
            if (file == null) return;
            ImageFrame ifr = new ImageFrame(file.getAbsolutePath());
            desktop.add(ifr, javax.swing.JLayeredPane.DEFAULT_LAYER);
            
            ifr.setVisible( true );
            ifr.setSize(200, 200);
            ifr.setLocation(0, 0);
        }
    }
 private static class ImageFileFilter extends javax.swing.filechooser.FileFilter {
        
        public boolean accept(java.io.File file) {
            if (file == null)
                return false;
            return file.isDirectory() || file.getName().toLowerCase().endsWith(".gif") || file.getName().toLowerCase().endsWith(".jpg");
        }
        
        public String getDescription() {
            return "Image files (*.gif, *.jpg)";
        }
        
    }
    public void openImageViaFile(java.io.File file) {
       
            if (file == null) return;
            ImageFrame ifr = new ImageFrame(file.getAbsolutePath());
            desktop.add(ifr, javax.swing.JLayeredPane.DEFAULT_LAYER);
            
            ifr.setVisible( true );
            ifr.setSize(200, 200);
            ifr.setLocation(0, 0);
      
    }

    private void exitForm(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_exitForm
        //System.exit(0);
    }
    

}